import { useEffect } from 'react'
import { useLocation, Route, Routes} from 'react-router-dom';
import Home from './page/Home/index';
import About from './page/About/index';

function App() {

  const location = useLocation()
  useEffect(() => {
    if (process.env.NODE_ENV === 'production') {
      fetch('./version.json', {
        method: "GET",
        headers: {
          'Cache-Control': 'no-cache',
        }
      }).then(res => res.json()).then(data => {
        const latestVersion = data[data.length - 1].version
        const currentVersion = Number(document.querySelector('meta[name="version"]')?.getAttribute('content'))
        if (latestVersion !== currentVersion) {
          console.log(latestVersion, currentVersion)
          alert(`版本升级中:  currentVersion: ${currentVersion}, latestVersion: ${latestVersion}`)
          window.location.reload()
        }
      })
    }
  }, [location])

  return (
    <>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
      </Routes>
    </>
  )
}

export default App
